
import pickle
from mmengine import load

# prefix = "train"
prefix = "val"

info_path4 = "/home/lin/code/bevdetv2.1/BEVDet/data/nuscenes/bevdetv2-nuscenes_infos_"+prefix+ "_src.pkl"
info_file = load(info_path4)
print(info_file.keys())

# print(info_file['metadata'])
print(len(info_file['infos']))

infos = []

print(info_file['infos'][0].keys())

for sample in info_file['infos']:
    # print(sample)
    # print("\n")
    print(sample.keys())
    break
    # print(sample['num_lidar_pts'])
    # print("\nann_infos:\n")
    # print(sample['ann_infos'][0][0].shape)
    # print(sample['cams'].keys())
    # print(sample['cams']['CAM_FRONT'])


    sample.pop("occ_path")
    sample.pop("scene_token")
    sample.pop("valid_flag")
    # sample.pop("token")
    # sample.pop("sweeps")
    # sample.pop("timestamp")
    sample.pop("num_radar_pts")
    sample.pop("num_lidar_pts")
    # print(sample.keys())

    infos.append(sample)

print(len(infos))

new_dict = {}
new_dict['metadata'] = info_file['metadata']
new_dict['infos'] = infos

# for i,j in enumerate(new_dict['infos']):
#     print(j.keys())


with open('./data/nuscenes/1%s_infos_%s.pkl' % ("nuscenes", prefix),
                'wb') as fid:
    pickle.dump(new_dict, fid)
